<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License. 
-->
<html>
<head>
    <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
    <style type="text/css">
        .dp-highlighter {
            width:95% !important;
        }
    </style>
    <style type="text/css">
        .footer {
            background-image:      url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
            background-repeat:     repeat-x;
            background-position:   left top;
            padding-top:           4px;
            color:                 #666;
        }
    </style>
    <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
    <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
    <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script>
    <script type="text/javascript">
        SyntaxHighlighter.defaults['toolbar'] = false;
        SyntaxHighlighter.all();
    </script>
    <script type="text/javascript" language="javascript">
        var hide = null;
        var show = null;
        var children = null;

        function init() {
            /* Search form initialization */
            var form = document.forms['search'];
            if (form != null) {
                form.elements['domains'].value = location.hostname;
                form.elements['sitesearch'].value = location.hostname;
            }

            /* Children initialization */
            hide = document.getElementById('hide');
            show = document.getElementById('show');
            children = document.all != null ?
                    document.all['children'] :
                    document.getElementById('children');
            if (children != null) {
                children.style.display = 'none';
                show.style.display = 'inline';
                hide.style.display = 'none';
            }
        }

        function showChildren() {
            children.style.display = 'block';
            show.style.display = 'none';
            hide.style.display = 'inline';
        }

        function hideChildren() {
            children.style.display = 'none';
            show.style.display = 'inline';
            hide.style.display = 'none';
        }
    </script>
    <title>Using Checkboxes - Velocity and HTML</title>
</head>
<body onload="init()">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr class="topBar">
        <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
            &nbsp;<a href="home.html">Home</a>&nbsp;&gt;&nbsp;<a href="faqs.html">FAQs</a>&nbsp;&gt;&nbsp;<a href="cookbook.html">Cookbook</a>&nbsp;&gt;&nbsp;<a href="using-checkboxes.html">Using Checkboxes</a>&nbsp;&gt;&nbsp;<a href="using-checkboxes-velocity-and-html.html">Using Checkboxes - Velocity and HTML</a>
        </td>
        <td align="right" valign="middle" nowrap>
            <form name="search" action="https://www.google.com/search" method="get">
                <input type="hidden" name="ie" value="UTF-8" />
                <input type="hidden" name="oe" value="UTF-8" />
                <input type="hidden" name="domains" value="" />
                <input type="hidden" name="sitesearch" value="" />
                <input type="text" name="q" maxlength="255" value="" />
                <input type="submit" name="btnG" value="Google Search" />
            </form>
        </td>
    </tr>
</table>

<div id="PageContent">
    <div class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
        <div style="margin: 0px 10px 8px 10px"  class="pagetitle">Using Checkboxes - Velocity and HTML</div>

        <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14063">
                <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14063">Edit Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
                <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14063">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14063">Add Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14063">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14063">Add News</a>
        </div>
    </div>

    <div class="pagecontent">
        <div class="wiki-content">
            <div id="ConfluenceContent">

<p>Velocity View - edit.vm:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;html&gt;
&lt;body onload="document.forms[0].elements[0].focus()"&gt;

&lt;a href="home.vm"&gt;Home&lt;/a&gt;&lt;br/&gt;

#if ($fieldErrors)
  #foreach ($error in $fieldErrors)
    $error&lt;br&gt;
  #end
#end
#if ($actionErrors)
  #foreach ($error in $actionErrors)
    $error&lt;br&gt;
  #end
#end

&lt;form name="edit" action="edit.action" method="post"&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;$user.username&lt;/td&gt;&lt;/tr&gt;
#formRowText("Password" "user.password" $stack.findValue("@cash.validator.PasswordFormatValidator@PASSWORD_MASK"))
#formRowText("Repeat Password" "repeatPassword" $stack.findValue("@cash.validator.PasswordFormatValidator@PASSWORD_MASK"))
#formRowText("Email" "user.email" $!user.email)
#formRowSelect("Language" "user.locale" $stack.findValue("@cash.util.Html@getInstance()").getLocales($locale) $!user.locale.toString())
#formRowSelect("Time Zone" "user.timeZone" $stack.findValue("@cash.util.Html@getInstance()").getTimeZones($locale) $!user.timeZone.ID)
#formRowText("Telephone" "user.telephone" $!user.telephone)
#formRowCheckbox("Locked Out" "user.lockedOut" "true" $user.lockedOut)
#formRowCheckbox("Disabled" "user.disabled" "true" $user.disabled)


#set ($privs = [OS:"boss", "admin", "early", "late", "train"])

#foreach ($priv in $privs)
  #set ($checked = $user.privileges.contains($priv))
  #formRowCheckbox($priv "user.priv" $priv $checked)
#end
&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&lt;input type="submit" name="submit" value="submit"&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

&lt;input type="hidden" name="user.username" value="$user.username"&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
</div></div>

<p>Velocity Macros - macros.vm:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
#macro (formRowText $label $name $value)
  &lt;tr&gt;&lt;td&gt;&lt;label for="$name"&gt;$label&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="$name" type="text" name="$name" value="$!value"&gt;&lt;/td&gt;&lt;/tr&gt;
#end

#macro (formRowSelect $label $name $options $selectedValue)
  &lt;tr&gt;&lt;td&gt;&lt;label for="$name"&gt;$label&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;select id="$name" name="$name"&gt;
#foreach ($option in $options)
&lt;option#if ($option.get(0).equals($selectedValue)) selected#end value="$option.get(0)"&gt;$option.get(1)&lt;/option&gt;
#end
&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
#end

#macro (formRowCheckbox $label $name $value $checked)
  &lt;tr&gt;&lt;td&gt;&lt;label for="$name.$value"&gt;$label&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="$name.$value" type="checkbox" name="$name" value="$value"#if ($checked) checked#end &gt;&lt;/td&gt;&lt;/tr&gt;
#end
</pre>
</div></div>

<p>Note that I don't use the webwork UI tags.  (The HTML that comes out of them looks like vomit.)</p>

<p>The HTML generated from above looks like:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;html&gt;
&lt;body onload="document.forms[0].elements[0].focus()"&gt;

&lt;a href="home.vm"&gt;Home&lt;/a&gt;&lt;br/&gt;

    
&lt;form name="edit" action="edit.action" method="post"&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;user&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;label for="user.password"&gt;Password&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="user.password" type="text" name="user.password" value="********"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;label for="repeatPassword"&gt;Repeat Password&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="repeatPassword" type="text" name="repeatPassword" value="********"&gt;&lt;/td&gt;&lt;/tr&gt;

  &lt;tr&gt;&lt;td&gt;&lt;label for="user.email"&gt;Email&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="user.email" type="text" name="user.email" value="user@example.com"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;label for="user.locale"&gt;Language&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;select id="user.locale" name="user.locale"&gt;
&lt;option value="en"&gt;English&lt;/option&gt;
&lt;option selected value="en_AU"&gt;English (Australia)&lt;/option&gt;
&lt;option value="en_US"&gt;English (United States)&lt;/option&gt;
&lt;option value="en_GB"&gt;English (United Kingdom)&lt;/option&gt;
&lt;option value="es"&gt;Spanish&lt;/option&gt;
&lt;option value="fr"&gt;French&lt;/option&gt;

&lt;option value="de"&gt;German&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;label for="user.timeZone"&gt;Time Zone&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;select id="user.timeZone" name="user.timeZone"&gt;
&lt;option selected value="America/Los_Angeles"&gt;(GMT-08:00) Los Angeles&lt;/option&gt;
&lt;option value="Europe/London"&gt;(GMT+00:00) London&lt;/option&gt;
&lt;option value="Australia/Brisbane"&gt;(GMT+10:00) Brisbane&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;label for="user.telephone"&gt;Telephone&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="user.telephone" type="text" name="user.telephone" value="134"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;label for="user.lockedOut.true"&gt;Locked Out&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="user.lockedOut.true" type="checkbox" name="user.lockedOut" value="true" &gt;&lt;/td&gt;&lt;/tr&gt;

  &lt;tr&gt;&lt;td&gt;&lt;label for="user.disabled.true"&gt;Disabled&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="user.disabled.true" type="checkbox" name="user.disabled" value="true" &gt;&lt;/td&gt;&lt;/tr&gt;



    &lt;tr&gt;&lt;td&gt;&lt;label for="user.priv.boss"&gt;boss&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="user.priv.boss" type="checkbox" name="user.priv" value="boss" &gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;&lt;label for="user.priv.admin"&gt;admin&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="user.priv.admin" type="checkbox" name="user.priv" value="admin" &gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;&lt;label for="user.priv.early"&gt;early&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="user.priv.early" type="checkbox" name="user.priv" value="early" &gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;&lt;label for="user.priv.late"&gt;late&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="user.priv.late" type="checkbox" name="user.priv" value="late" &gt;&lt;/td&gt;&lt;/tr&gt;

    &lt;tr&gt;&lt;td&gt;&lt;label for="user.priv.train"&gt;train&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input id="user.priv.train" type="checkbox" name="user.priv" value="train" &gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&lt;input type="submit" name="submit" value="submit"&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

&lt;input type="hidden" name="user.username" value="user"&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
</div></div></div>
        </div>

        
    </div>
</div>
<div class="footer">
    Generated by CXF SiteExporter
</div>
</body>
</html>
